﻿namespace ``Concerning the assertion syntax``

open FSpec
open System
open System.Linq

module ``Exceptions``=
    let ``it fail should.throw - no exception``()=
        capture(fun() -> 

            (fun()-> 
                let i = 0
                ignore()
            )|> should.throw typeof<InvalidOperationException>

        ).Description
        |> should.equal (format 
                            Resources.TheExpressionShouldThrowA_0_ 
                            [ typeof<InvalidOperationException> ])

    let ``it fail should.throw - wrong exception``()=
        capture(fun() -> 

            (fun() -> 
                invalidArg "sixTimesNine" "must equal 42"
            ) |> should.throw typeof<InvalidOperationException>   

        ).Description
        |> should.equal (format 
                            Resources.TheExpressionShouldThrowA_0_ 
                            [ typeof<InvalidOperationException> ])

    let ``it fail shouldNot.throw``()=
        capture(fun() -> 
         
            (fun()->raise(invalidOp ""))
            |> shouldNot.throw typeof<InvalidOperationException> 

        ).Description
        |> should.equal (format 
                            Resources.TheExpressionShouldNotThrowA_0_ 
                            [ typeof<InvalidOperationException> ])

    let ``it fail should.failWith - wrong message``()=
        capture(fun() ->
         
            (fun()-> failwith "wrong message")
            |> should.failWith "a message"

        ).Description 
        |> should.equal (format
                            Resources.TheExpressionShouldFailWithTheMessage_0_
                            [ "a message" ])


    let ``it fail shouldNot.failWith - wrong message``()=
        capture(fun() ->
         
            (fun()-> failwith "a message")
            |> shouldNot.failwith "a message"

        ).Description 
        |> should.equal (format
                            Resources.TheExpressionShouldNotFailWithTheMessage_0_
                            [ "a message" ])                                        
    
    
    
       